<?php

/**
 * This is the model class for table "{{article}}".
 *
 * The followings are the available columns in table '{{article}}':
 * @property integer $articleID
 * @property integer $vendorID
 * @property integer $userID
 * @property string $article_title
 * @property string $article_desc
 * @property string $article_file
 * @property string $article_intro
 * @property string $created
 * @property string $modified
 */
class Article extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Article the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{article}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('vendorID, userID, article_title, article_desc, article_type', 'required'),
			array('vendorID, userID', 'numerical', 'integerOnly'=>true),
			array('article_title', 'length', 'max'=>200),
			array('article_desc, article_file, article_intro', 'length', 'max'=>500),
                        array('modified','default',
                              'value'=>new CDbExpression('NOW()'),
                              'setOnEmpty'=>false,'on'=>'update'),
                       array('created,modified','default',
                             'value'=>new CDbExpression('NOW()'),
                              'setOnEmpty'=>false,'on'=>'insert'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('articleID, vendorID, userID, article_title, article_desc, article_file, article_intro, created, modified', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'articleID' => 'Article',
			'vendorID' => 'Vendor',
			'userID' => 'User',
			'article_title' => 'Article Title',
			'article_desc' => 'Article Desc',
			'article_file' => 'Article File',
			'article_intro' => 'Article Intro',
                        'article_type'=>'Article Type',
                        'enable'=>'Approve',
			'created' => 'Created',
			'modified' => 'Modified',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('articleID',$this->articleID);
		$criteria->compare('vendorID',$this->vendorID);
		$criteria->compare('userID',$this->userID);
		$criteria->compare('article_title',$this->article_title,true);
		$criteria->compare('article_desc',$this->article_desc,true);
		$criteria->compare('article_file',$this->article_file,true);
		$criteria->compare('article_intro',$this->article_intro,true);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('modified',$this->modified,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
        
        public static function getList($type,$arrParams)
        {
            switch ($type)
            {
                case 'LATEST-ARTICLE':
                return Article::model()->findAll(array('order'=>'articleID DESC','limit'=>'10'));
                break;    
            }
       
            
       }
}